<?php
	require_once 'Connect.class.php';
	require_once 'DanhMuc.class.php';
	/**
	* 
	*/

	class KyLuat extends DanhMuc
	{
		
		public function __construct()
		{
			# code...
		}

		public function getInfo($maLoaiKL){

			$conn= new Connect();

			$conn->Query("SELECT * FROM tbl_loai_ky_luat WHERE maLoaiKL='".$maLoaiKL."'; ");	

			while ($row=$conn->Fetch()) {	

				$this->ma=$row['maLoaiKL'];
				
				$this->ten=$row['tenLoaiKL'];
			}
			// dong ket noi
			$conn->close();
		}

		public function them(){

			$sql="INSERT INTO tbl_loai_ky_luat(maLoaiKL,tenLoaiKL) values('".$this->ma."','".$this->ten."')";

			$conn=new Connect();

			$conn->Query($sql);

			$conn->close();
			
		}

		public function xoa(){
			
			$sql="DELETE FROM tbl_loai_ky_luat WHERE maLoaiKL='".$this->ma."'";
			
			$conn=new Connect();
			
			$conn->Query($sql);
			
			$conn->close();

		}
		public function checkNo($maLoaiKL){

			$rs=false;

			$conn= new Connect();

			$conn->Query("SELECT COUNT(maLoaiKL) as dem FROM tbl_loai_ky_luat WHERE maLoaiKL='".$maLoaiKL."'; ");	

			while ($row=$conn->Fetch()) {	
				if ($row['dem']==1){
					$rs=true;
				}
			}
			// dong ket noi
			$conn->close();
			return $rs;
		}
		public function capnhat(){
			$sql="UPDATE tbl_loai_ky_luat SET tenLoaiKL='".$this->ten."' WHERE maLoaiKL='".$this->ma."'";
		
			$conn=new Connect();
		
			$conn->Query($sql);
		
			$conn->close();
		}

		//---hàm lấy danh sách chức vụ
		public function ds(){
			$ds=array();
			$conn= new Connect();
			$conn->Query("SELECT * FROM tbl_loai_ky_luat");
			$index=0;
			while ($row=$conn->Fetch()) {
				$kl= new KyLuat();
				$kl->setMa($row['maLoaiKL']);
				$kl->setTen($row['tenLoaiKL']);
				$ds[$index]=$kl;
				$index++;
			}
			// dong ket noi
			$conn->close();
			return $ds;
		}
	}
?>

